package org.example.threadorder;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.locks.LockSupport;

/**
 * @author zhengdp
 * @Description 线程顺序控制(Park & UnPark)
 * @Date 2022/11/9 22:24
 * @Created by zhengdp
 */
@Slf4j(topic = "c.ThreadOrderParkUnPark")
public class ThreadOrderParkUnPark {
    public static void main(String[] args) {

        Thread t1 = new Thread(() -> {
            LockSupport.park();
            log.info("1");
        },"t1");

        t1.start();
        new Thread(() -> {
            log.info("2");
            // t2 先运行，提前为t1准备好信号量（吃饱好上路）
            LockSupport.unpark(t1);
        },"t2").start();
    }
}
